﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNETPerformance.App_BusinessLogic.BasePages;
using ASPNETPerformance.App_BusinessLogic.Helpers;
using ASPNETPerformance.App_BusinessLogic.Utils;

namespace ASPNETPerformance.UserControls {
    public partial class Part7 : BaseUserControl {
        protected void Page_Load( object sender, EventArgs e ) {
            if ( !this.Page.IsPostBack ) {
                BindPart7();
            }
        }

        private void BindPart7() {
            this.cbEnableCdnJquery.Checked = CommonHelper.GetCookieBool( "IsCdnJquery" );
            this.cbEnableCdnServer1.Checked = CommonHelper.GetCookieBool( "IsEnableCdnServer1" );
            if ( this.cbEnableCdnServer1.Checked ) {
                this.txtCdnServerAddress1.Text = CommonHelper.GetCookieString( "CdnServerHost1", true );
            }
        }

        protected void BtnPart7_Click( object sender, EventArgs e ) {
            SaveInfo();

            this.lblPart7Result.Text = "保存成功。";
        }

        public void SaveInfo() {
            CommonHelper.SetCookie( "IsCdnJquery",
                this.cbEnableCdnJquery.Checked.ToString(), new TimeSpan( 365, 0, 0, 0, 0 ) );

            CommonHelper.SetCookie( "IsEnableCdnServer1",
                this.cbEnableCdnServer1.Checked.ToString(), new TimeSpan( 365, 0, 0, 0, 0 ) );
            if ( this.cbEnableCdnServer1.Checked ) {
                CommonHelper.SetCookie( "CdnServerHost1",
                    this.txtCdnServerAddress1.Text, new TimeSpan( 365, 0, 0, 0, 0 ) );
            }
        }
    }
}